/**
 * date :2010-11-10
 * comment : 
 * 
 * 			BoardDAOImpl
 * 
 */
package wetogether.community.dao;

import java.sql.SQLException;
import java.util.ArrayList;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import wetogether.community.vo.AttachmentVO;
import wetogether.community.vo.BoardVO;
import wetogether.community.vo.CommentsVO;
import wetogether.community.vo.ContentListVO;

public class BoardDAOImpl extends SqlMapClientDaoSupport implements BoardDAO {
	/*
	 * 글, 댓글, 첨부파일 삭제
	 */
	@Override
	public void deleteAttachment(int fileId) throws SQLException {
		this.getSqlMapClientTemplate().delete("board.deleteAttachment", fileId);
	}

	@Override
	public void deleteComments(int commentsId) throws SQLException {
		this.getSqlMapClientTemplate().delete("board.deleteComments", commentsId);
	}

	@Override
	public void deleteContent(int contentId) throws SQLException {
		this.getSqlMapClientTemplate().delete("board.deleteContent", contentId);
	}

	/*
	 * 글 검색
	 * 따로 메서드 만들 필요 없음!!
	 * 목록 뽑을 때 검색어가 없다면 전체 글 목록으로 보여주고, 검색어가 있다면 해당 검색어에 맞는 글 목록을 보여준다.
	 */
	/*@Override
	public ArrayList<BoardVO> findContentByName(String name, int boardId, int locationId) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ArrayList<BoardVO> findContentByTitle(String title, int boardId, int locationId) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}*/



	/*
	 * 2010-11-08
	 * 해당 시퀀스의 글이 입력된 날짜를 얻어오는 메서드.
	 * Content, Comments, Attachment 각각 입력 시 시퀀스 값이 필요하므로
	 * 여러 개의 메서드보다는 하나의 메서드에서 
	 * 각각에 해당하는 시퀀스 값을 받아오고 type 을 비교해서 해당 쿼리를 실행한다.
	 */
	@Override
	public String getContentDate(int seq) throws SQLException {
		return (String) super.getSqlMapClientTemplate().queryForObject("board.getContentRegDate", seq);
	}
	@Override
	public String getCommentsDate(int seq) throws SQLException {
		return (String) super.getSqlMapClientTemplate().queryForObject("board.getCommentsRegDate", seq);
		
	}
	@Override
	public String getAttachmentDate(int seq) throws SQLException {
		return (String) super.getSqlMapClientTemplate().queryForObject("board.getAttachmentsRegDate", seq);
	}
	
	/*
	 * 글, 글 목록, 첨부파일, 댓글 목록 보기
	 */
	@Override
	public BoardVO getContent(int contentId) throws SQLException {
		return (BoardVO)this.getSqlMapClientTemplate().queryForObject("board.getContent", contentId);
	}

	@Override
	public AttachmentVO getAttachment(int contentId) throws SQLException {
		return (AttachmentVO)this.getSqlMapClientTemplate().queryForObject("board.getAttachment", contentId);
	}
	
	/**
	 * 목록 뽑을 때 검색어가 없다면 전체 글 목록으로 보여주고, 검색어가 있다면 해당 검색어에 맞는 글 목록을 보여준다.
	 */
	@Override
	public ArrayList<BoardVO> getContentList(ContentListVO contentListVO) {
		return (ArrayList<BoardVO>)this.getSqlMapClientTemplate().queryForList("board.getContentList", contentListVO);
	}
	
	@Override
	public ArrayList<CommentsVO> getCommentsList(int contentId) throws SQLException {
		return (ArrayList<CommentsVO>)this.getSqlMapClientTemplate().queryForList("board.getCommentsList", contentId);
	}
	
	/*
	 * 시퀀스 가져오기
	 */
	@Override
	public int getSelectAttachmentSeq() throws SQLException {
		return (Integer)this.getSqlMapClientTemplate().queryForObject("board.getSelectAttachmentSeq");
	}

	@Override
	public int getSelectCommentsSeq() throws SQLException {
		return (Integer)this.getSqlMapClientTemplate().queryForObject("board.getSelectCommentsSeq");
	}

	@Override
	public int getSelectContentSeq() throws SQLException {
		return (Integer)this.getSqlMapClientTemplate().queryForObject("board.getSelectContentSeq");
	}
	
	/*
	 * 글, 댓글, 첨부파일 입력
	 */
	@Override
	public void insertAttachment(AttachmentVO attachmentVO) throws SQLException {
		this.getSqlMapClientTemplate().insert("board.insertAttachment", attachmentVO);
	}

	@Override
	public void insertComments(CommentsVO commentsVO) throws SQLException {
		System.out.println("dao : " + commentsVO.toString());
		this.getSqlMapClientTemplate().insert("board.insertComments", commentsVO);
	}

	@Override
	public void insertContent(BoardVO boardVO) throws SQLException {
		this.getSqlMapClientTemplate().insert("board.insertContent", boardVO);
	}
	
	/*
	 * 글 총 개수 
	 */
	@Override
	public int totalContent(ContentListVO contentListVO) {
		return (Integer)this.getSqlMapClientTemplate().queryForObject("board.totalContent", contentListVO);
	}

	/*
	 * 게시물 commentsHits 올리기
	 */
	@Override
	public void updateCommentsHitsUp(int contentId) throws SQLException {
		super.getSqlMapClientTemplate().update("board.updateCommentsHitsUp", contentId);
	}
	
	@Override
	public void updateCommentsHitsDown(int contentId) throws SQLException {
		super.getSqlMapClientTemplate().update("board.updateCommentsHitsDown", contentId);
	}
	
	/*
	 * 글 수정
	 */
	@Override
	public void updateContent(BoardVO boardVO) throws SQLException {
		System.out.println("###in updateContent##: "+boardVO);
		this.getSqlMapClientTemplate().update("board.updateContent", boardVO);
	}

	
	/*
	 * 주석 달아주세요~~
	 */
	@Override
	public void updateDownload(int fileId) {
		this.getSqlMapClientTemplate().update("board.updateDownload", fileId);
	}

	@Override
	public void updateHits(int contentId) throws SQLException {
		this.getSqlMapClientTemplate().update("board.updateHits", contentId);
	}

	@Override
	public void updatePositionNumber(BoardVO boardVO) {
		getSqlMapClientTemplate().update("board.updatePositionNumber", boardVO);
	}
	
	@Override
	public int checkGroupPosition(BoardVO boardVO) {
		return (Integer)getSqlMapClientTemplate().queryForObject("board.checkGroupPosition", boardVO);
	}
	
	@Override
	public int findMaxGroupPosition(BoardVO boardVO) {
		return (Integer)getSqlMapClientTemplate().queryForObject("board.findMaxGroupPosition", boardVO);
	}
}